#ifndef __MD_AS5600_H
#define __MD_AS5600_H

#include "main.h"
#include "math.h"
#include "stdlib.h"
#include "algorithm.h"
#include "foc.h"

#define AS5600_ADDRESS_MAG           0x36

typedef enum
{
/* set i2c address */ 
  _ams5600_Address = 0x36,
  _zmco = 0x00,
  _zpos_hi = 0x01,
  _zpos_lo = 0x02,
  _mpos_hi = 0x03,
  _mpos_lo = 0x04,
  _mang_hi = 0x05,
  _mang_lo = 0x06,
  _conf_hi = 0x07,    
  _conf_lo = 0x08,
  _raw_ang_hi = 0x0c,
  _raw_ang_lo = 0x0d,
  _ang_hi = 0x0e,
  _ang_lo = 0x0f,
  _stat = 0x0b,
  _agc = 0x1a,
  _mag_hi = 0x1b,
  _mag_lo = 0x1c,
  _burn = 0xff
}AMS5600Registers_t;

typedef enum
{
	MD = 0x01 << 5,
	ML = 0x01 << 4,
	MH = 0x01 << 3
}as5600_status_e;

typedef struct
{
	uint8_t read_data[3];
	int angle,last_angle;
	int angle_velocity,last_angle_velocity;
	uint8_t status;
	filter_int_t flp_angle_velocity;
}as5600_data_t;

void as5600_init(as5600_data_t *asdata,float lp_a);
void as5600_angle_analytical(as5600_data_t *asdata,uint32_t sampling_time);
void as5600_status_analytical(as5600_data_t *asdata);

#endif 
		
